package road;
import neighborhood.*;

/**
 * The purpose of the Road class is to define the speeds at which cars travel
 * between cities. This road must contain data regarding speeds, sizes, car
 * capciaties and the neighborhoods which it services. Note: Lane Size is the
 * factor not the actual number of lanes. Car Capacity is the total number of
 * cars that can be placed on the road per minute.
 * 
 * @author Tean Switchboard Boxcar
 * 
 */
public class Road
{
	private int MaxSpeed;
	private int CurrentSpeed;
	private int OriginalLaneSize;
	private double LaneSizeMultiplier;
	private int CarsPerMin;
	private int Length;
	private int EndingNeighborhood;
	
	/**
	 * Road is the basic constructor for the road class. It takes in all of the
	 * initial preconditions and builds a road that will take cars between two
	 * neighborhoods.
	 * 
	 * @param MaxSpd
	 *            The Maximum Speed that a car can travel between two cities in
	 *            miles per hour.
	 * @param LnSize
	 *            The Lane Size for a road between two cities. This expects
	 *            Original Lane Size.
	 * @param RdLength
	 *            This is the length of the road between two cities in miles.
	 * @param LnMult
	 *            This is the lane multiplier which is based upon the number of
	 *            lanes a user adds to a road.
	 * @param EndNeigh
	 *            This is the ending neighborhood for the road.
	 */
	public Road(int MaxSpd, int LnSize, int RdLength, 
				double LnMult, int EndNeigh)
	{
		MaxSpeed = MaxSpd;
		CurrentSpeed = MaxSpd;
		OriginalLaneSize = LnSize;
		Length = RdLength;
		EndingNeighborhood = EndNeigh;
		LaneSizeMultiplier = LnMult;
		
		CarsPerMin = (int)(OriginalLaneSize * LaneSizeMultiplier * MaxSpeed) ;
	}
	
	/**
	 * GetTravelTime returns the time it takes travel the length of this road.
	 * 
	 * @return This returns a ceiling value for the total travel time in minutes
	 */
	public int GetTravelTime()
	{	return (int)(((double)(Length -1 ) / (double)(CurrentSpeed+1)) * 60); 	}
	
	/**
	 * The UpdateSpeed function updates the current speed of a road. This value
	 * can be changed due to waeather or traffic conditions.
	 * 
	 * @param speedMultiplier
	 *            This is a factor which represents the percent change in the
	 *            current speed of the road.
	 */
	public void UpdateSpeed(double speedMultiplier) {
		CurrentSpeed *= speedMultiplier;
		CarsPerMin = (int)(OriginalLaneSize * LaneSizeMultiplier * CurrentSpeed);
	}
	
	/**
	 * ResetSpeed resets the Current Speed to the Maximum Speed. This will be
	 * called when an accident is resolved.
	 */
	public void ResetSpeed()
	{CurrentSpeed = MaxSpeed;}
	
	/**
	 * GetCarsPerMin is the function called when a neighborhood needs to release
	 * cars onto a road to travel to an adjacent neighborhood.
	 * 
	 * @return This returns the integer value of total cars per minute that can
	 *         travel on a road.
	 */
	public int GetCarsPerMin()
	{	return CarsPerMin; }

	/**
	 * GetEndNeighborhood returns the ending neighborhood for a specific road.
	 * This is used to determine where to place whether cars have reached their
	 * final destination.
	 * 
	 * @return The Neighborhood destination of a specific road.
	 */
	public int GetEndNeighborhood()
	{ return EndingNeighborhood; }
	
}